import * as file from './file';
import * as bool from './bool';
import * as tool from './tool';
import { THEME } from '@B/themesConfig';

/** getLog (常量枚举映射)方法说明
* @author: JasonStandFor
* @description Desc:: 改写 console 输出，添加样式后输出
* @param {String} enterText - 只支持字符串改写输出
* @param {String|CSSStyleDeclaration} colorType - 控制输出字符颜色
* @return console.info
**/
export const getLog = (enterText = '调试日志', colorType = `color: ${THEME.primaryColor}`) => {
  console.info(
    `%c${enterText}`,
    `${colorType};font-size:1.5em`
  //   `text-shadow: 0 1px 0 #ccc,
  // 0 2px 0 #c9c9c9,
  // 0 3px 0 #bbb,
  // 0 4px 0 #b9b9b9,
  // 0 5px 0 #aaa,
  // 0 6px 1px rgba(0,0,0,.1),
  // 0 0 5px rgba(0,0,0,.1),
  // 0 1px 3px rgba(0,0,0,.3),
  // 0 3px 5px rgba(0,0,0,.2),
  // 0 5px 10px rgba(0,0,0,.25),
  // 0 10px 10px rgba(0,0,0,.2),
  // 0 20px 20px rgba(0,0,0,.15);
  // font-size:2em`
  );
}

/** constantListMapping (常量枚举映射)方法说明
* @author: JasonStandFor
* @description Desc:: 映射 code/name or other => value/label
* @param {Array} arr - object 实例对象
* @return Object
* @example:
const statusList = [
 { value: 'effective', label: '生效' },
 { value: 'invalid', label: '失效' },
 { value: 'pending', label: '待生效' }
];
const STATUS_LIST_MAP = constantListMapping(statusList);
STATUS_LIST_MAP['effective']  => '生效'
**/
export const constantListMapping = (arr = []) => {
  if (!Array.isArray(arr)) return {};
  return arr.reduce((result, item = {}) => {
    if (bool.notEmptyObject(item['value'])) result[item['value']] = item['label'] || undefined;
    // 视情况而加，目前先注释
    // if (bool.notEmptyObject(item['label'])) result[item['label']] = item['value'] || undefined;
    return result || undefined;
  }, {});
};

/** uuid (通用唯一识别码)方法说明
 * @author: JasonStandFor
 * @description Desc:: 让分布式系统中的所有元素，都能有唯一的辨识信息，而不需要通过中央控制端来做辨识信息的指定。
 * @return string|uuid
 * @example
 // 每次生成不重复的识别码
 uuid() // a640be34-689f-4b98-be77-e3972f9bffdd
 **/
export const uuid = () => {
  const temp_url = URL.createObjectURL(new Blob());
  const uuid = temp_url.toString();
  URL.revokeObjectURL(temp_url); // 释放这个url
  return uuid.substring(uuid.lastIndexOf('/') + 1);
};

export default {
  ...bool,
  ...tool,
  ...file,
};
